package com.gis.bigdata.spark.core.framework.common

import com.gis.bigdata.spark.core.framework.controller.WordCountController
import com.gis.bigdata.spark.core.framework.util.{EnvUtil}
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author LnnuUser
 * @create 2021-09-02-上午9:17
 */
trait TApplication {

  def start(master: String = "local[*]", app: String = "Application")( op: => Unit ) = {
    val sparkConf = new SparkConf().setMaster(master).setAppName(app)
    val sc = new SparkContext(sparkConf)
    EnvUtil.put(sc)


    try {
      op
    }catch {
      case ex => println(ex.getMessage)
    }

    //TODO 关闭连接
    sc.stop()
    EnvUtil.clear()
  }

}
